import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

function resolve(dir : string) : string {
    return path.join(__dirname, dir)
}

const isProd = process.env.NODE_ENV === 'production'

const useRemote =  true;
const useHttps = useRemote ? false : false;
const proxyRemote = useRemote ? "cxwv4.ricebird.cn" : "localhost:6435" // "127.0.0.1:7253" // 

// https://vitejs.dev/config/
export default defineConfig({
    base: process.env.NODE_ENV === "production" ? "/manage/" : "/",
    plugins: [ vue() ],
    build: {
        target:['edge90','chrome90','firefox90','safari15'] // 2021年以后的浏览器均可使用
    },
    css: {
        preprocessorOptions: {
            less: {
                charset: false,
                additionalData: '@import "@/assets/mixin.less";'
            }
        }
    },    
    resolve: {
        alias: [
            {
                find: "@",
                replacement: resolve('src')
            },
            {
                find: "@vc",
                replacement: resolve('src/cores')
            },
            {
                find: "@vm",
                replacement: resolve('src/modules')
            },
            {
                find: "@layouts",
                replacement: resolve('src/layouts')
            },
            {
                find: "@proj",
                replacement: resolve('src/modules/projects')
            }
        ]
    },
    server: {
        proxy: {            
            "/api": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`, 
                changeOrigin: true,
                secure: false,
            },
            "/signalr": {
                target: `${useHttps ? "wss" : "ws"}://${proxyRemote}`,
                changeOrigin: true,
                ws: true,
                secure: false,
            },
            "/debug": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`, 
                changeOrigin: true,
                secure: false,
            },
            "/permanent": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`, 
                changeOrigin: true,
                secure: false,
            },            
        }
    }
})
